package edu.mobbuzz.web.pages;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.Retain;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;

import edu.mobbuzz.daf.bean.Subscriber;
import edu.mobbuzz.daf.dao.ISubscriberDao;
import edu.mobbuzz.web.base.SecureBasePage;

public class SubscriberGridPage extends SecureBasePage{
	@Inject
	private ISubscriberDao userDao;
	
	private List<Subscriber> subscriberList;
	@Property
	private Subscriber subscriber;
	
	@Retain
	private BeanModel subscriberModel;
	@Inject
	private BeanModelSource beanModelSource;
	@Inject
	private ComponentResources resources;
	
	public ISubscriberDao getSubscriberDao() {
		return userDao;
	}
	
	public BeanModel getSubscriberModel() {
		return subscriberModel;
	}	
	
	public List<Subscriber> getSubscriberList() {
		if(subscriberList==null){
			subscriberList = new ArrayList<Subscriber>();
		}
		subscriberList = getSubscriberDao().queryForList("", "");		
		return subscriberList;
	}

	public void setSubscriberList(List<Subscriber> subscriberList) {
		this.subscriberList = subscriberList;
	}

	void pageLoaded(){
		subscriberModel = beanModelSource.createDisplayModel(Subscriber.class, resources.getMessages());
	
	}
}
